/**
 * Created by ritamashin on 2017/11/8.
 */
const initialState = {
    bannerData : [],
    secondBannerData : [],
    recommendHeaderData : [],
    giftItemsData : [],
    tagIdOffsetObj : {},
    isLoadMoreData : false,
};

export default (state = initialState, action) => {
    switch (action.type){

        case 'HOMEPAGE_APPEND_BANNER_DATA':{
            let {bannerData} = action;

            return {
                ...state,
                bannerData
            }
        }
        case 'HOMEPAGE_APPEND_SECOND_BANNER_DATA':{
            let {secondBannerData} = action;
            return {
                ...state,
                secondBannerData
            }
        }
        case 'HOMEPAGE_APPEND_RECOMMEND_HEADER_DATA':{
            let {recommendHeaderData} = action;

            return {
                ...state,
                recommendHeaderData
            }
        }
        case 'HOMEPAGE_APPEND_GIFT_DATA':{
            let {giftItemsData,tagId, offset, index} = action;
            offset = offset / 20;
            if (Number.parseInt(offset) === 0){
                let tagIdOffsetObj = {tagId,
                    index,
                    offset : (Number.parseInt(offset) + 1) * 20} ;
                return {
                    ...state,
                    giftItemsData,
                    tagIdOffsetObj,
                }
            }else if(Number.parseInt(offset) >= 1) {
                let tagIdOffsetObj = {tagId,
                    index,
                    offset : (Number.parseInt(offset) + 1) * 20} ;
                let oldData = state['giftItemsData'];
                giftItemsData.push(...oldData);
                return {
                    ...state,
                    giftItemsData,
                    tagIdOffsetObj,
                }
            }
        }
        case 'HOMEPAGE_SET_REFRESHING':{
            let {isLoadMoreData} = action;
            return {
                ...state,
                isLoadMoreData
            }
        }

        default :
            return state;

    }

}